<?php
include('config.php');
$type_name = isset($_POST['type']) ? $_POST['type'] : '';
$name_name = isset($_POST['name']) ? $_POST['name'] : '';
$number_name = isset($_POST['number']) ? $_POST['number'] : '';
$weight = isset($_POST['weight']) ? $_POST['weight'] : '';
$price = isset($_POST['price']) ? $_POST['price'] : '';
$time = isset($_POST['time']) ? $_POST['time'] : '';
$time = time();
$rs = $mysql->selectList('number',"number_name='{$number_name}'");
$number_id = $rs[0]['number_id'];
$where = "number_id={$number_id}";
$re = $mysql->selectList('stock',$where);
if($re){

	$id = $re[0]['stock_id'];
	$num = $re[0]['stock_num'];
	$numb = $re[0]['stock_goods_num'];
	$stock_number= $num + $weight;
	$total_stock_number = $numb + $weight;
	$data = array('type_id'=>$rs[0]['type_id'],'breed_id'=>$rs[0]['breed_id'],'number_id'=>$number_id,'stock_goods_num'=>$weight,'stock_goods_price'=>$price,'stock_goods_time'=>$time);
	$id1 = $mysql->insert('stock_goods_log',$data);
	$data1 = array('stock_num'=>$stock_number,'stock_goods_num'=>$total_stock_number);
	$where1 = "stock_id={$id}";
	$id = $mysql->update('stock', $where1, $data1);

	if($id && $id1){
		echo "1";
	}else{
		echo "-1";
	}
}
else{
	$data = array('type_id'=>$rs[0]['type_id'],'breed_id'=>$rs[0]['breed_id'],'number_id'=>$number_id,'stock_goods_num'=>$weight,'stock_goods_price'=>$price,'stock_goods_time'=>$time);
	$data1 = array('type_id'=>$rs[0]['type_id'],'breed_id'=>$rs[0]['breed_id'],'number_id'=>$number_id,'stock_goods_num'=>$weight,'stock_num'=>$weight);
	$id = $mysql->insert('stock_goods_log',$data);
	$id1 = $mysql->insert('stock',$data1);
	if($id>0 && $id1>0){
		echo "1";
	}else{
		echo -1;
	}
}